/*
 * @Author: linzaifei 1609781601@qq.com
 * @Date: 2025-07-24 10:52:39
 * @LastEditors: linzaifei 1609781601@qq.com
 * @LastEditTime: 2025-07-28 09:55:17
 * @FilePath: /amap-web-vr/src/views/home/control/vc-pitch-control/useCesiumCenter.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as Cesium from 'cesium';

export const useCesiumCenter = () => {
    
    const getCenter = (viewer: Cesium.Viewer) => {
            const scene = viewer.scene;
            const canvas = scene.canvas;

            const center = new Cesium.Cartesian2(canvas.clientWidth / 2.0, canvas.clientHeight / 2.0);
            const ellipsoid = viewer.scene.globe.ellipsoid;
            const result = viewer.camera.pickEllipsoid(center, ellipsoid);
            
            if (result) {
                let cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result);
                const longitude = Cesium.Math.toDegrees(cartographic.longitude);
                const latitude = Cesium.Math.toDegrees(cartographic.latitude);
                return {
                    longitude,
                    latitude
                }               
            }
            return null  
    }
    return {
        getCenter
    }

}